﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="hrEmpNoCardData.aspx.cs" Inherits="ZX.WebApp.EHR.hrEmpNoCardData" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无需打卡员工选择</title>
    <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
     <script type="text/javascript" src="../Scripts/Jquery.form.js"></script>
     <script type="text/javascript" src="../Scripts/CombinButton.js"></script>
    <script type="text/javascript">
    // <![CDATA[
        $(document).ready(function () {
            parent.document.getElementById("dialog1_h").innerHTML = "无需打卡员工选择";
            addtr();
        });

         //选择员工
         var employeeId;
         var ValueChanged = function (rowobj) {
             employeeId = $("#empId").val();
         }

         var TextChanged = function (rowobj) {
             var employeeName = $("#txtempId").val();
             if (employeeId == "" || employeeId == "undefined") {
                 return;
             }
             if (employeeName == "" || employeeName == "undefined") {
                 return;
             }
             //debugger
             $("#txtEmployeeID", rowobj).val(employeeName);
             $("#EmployeeID", rowobj).val(employeeId);
             GetDeptNameByEmpID(employeeId);
             GetPostNameByEmpID(employeeId);
             GetEmpcodeByEmpID(employeeId);
         }

         //获取员工所属部门名称
         function GetDeptNameByEmpID(empId) {
             var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
             $.get(url, function (d, s) {
                 var list = eval("(" + d + ")");
                 for (var o in list.rows) {
                     var t = list.rows[o].DeptName;
                     if (typeof (t) != "undefined") {
                         $("#DeptName", rowobj).val(t);
                     }
                 }
             });
         }

         //获取员工所属岗位名称
         function GetPostNameByEmpID(empId) {
             var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
             $.get(url, function (d, s) {
                 var list = eval("(" + d + ")");
                 for (var o in list.rows) {
                     var t = list.rows[o].PostName;
                     if (typeof (t) != "undefined") {
                         $("#PostName", rowobj).val(t);
                     }
                 }
             });
         }

         //获取员工编号
         function GetEmpcodeByEmpID(empId) {
             var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
             $.get(url, function (d, s) {
                 var list = eval("(" + d + ")");

                 for (var o in list.rows) {
                     var t = list.rows[o].EmployeeCode;
                     if (typeof (t) != "undefined") {
                         $("#EmployeeCode", rowobj).val(t);
                     }
                 }

             });
         }

         //增加行
         function addtr() {
             var tr = $("#tbEmp tr").eq(1).clone();
             tr.show();
             tr.appendTo("#tbEmp").removeClass("selectedTr").find(":checkbox").attr("checked", false);
         }

         //删除行
          function deltr() {
             //遍历tr
              $("#tbEmp tr").first().nextAll().each(function () {
                  if ($(this).hasClass("selectedTr")) {                      
                      $(this).remove();
                  }
              });
         };

         //选中行
         $("tr").live("click", function () {
             if ($(this).hasClass("selectedTr")) {
                 $(this).removeClass("selectedTr").find(":checkbox").attr("checked", false);
             } else {
                 $(this).addClass("selectedTr").find(":checkbox").attr("checked", true);
             }
         });

         //数据保存
         function Save() {
             //debugger;
             var ids = "";
             //遍历所有已选择员工
             $("#tbEmp tr").first().nextAll().each(function () {
                 var id = $("#EmployeeID", this).val();
                 if ($("#EmployeeID", this).val() != "") {
                     ids += "," + id;
                 }
             });
             if (ids != "") {
                 ids = ids.substring(1, ids.length);
             }
             else {
                 alert("请至少选择一个员工！");
                 return;
             }
             
             //提交数据
             YAHOO.util.Connect.asyncRequest('POST', "workTimeAjax.aspx?flag=saveNoCardData&ids=" + ids + "&entity=PERSON", {
                 success: function (res) {
                     try {
                         var str = res.responseText;
                         if (str.substring(0, 1) == "1") {
                             alert("数据保存成功!");
                             parent.closeWin();
                             parent.ReLoadData();
                         }
                         else {
                             alert("数据保存失败,请检查");
                         }
                     }
                     catch (e) {
                     }
                     finally {
                     }
                 },
                 failure: function (error) {
                     alert("数据错误：" + error.statusText);
                 }
             }, null);
         }
    // ]]> 
     </script>
     <style type="text/css">
    body{font-family: 宋体, Arial, Helvetica, sans-serif;font-size: 12px;color: #333333;background-color: #FFFFFF;} 
    select{width:99%;} td { border: 1px solid #CCCCCC;}
    .textarea{ width: 96%;height: 25px;}	
   .selectedTr{  background-color: blue;} 
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <input id="empId" name="empId" type="hidden" /> <input id="txtempId" name="txtempId" type="hidden" />
    <div id="divBtn">
        <input type="button" id="btnADD" value="新增" onclick="addtr();" />
        <input type="button" id="btnDEL" value="删除" onclick="deltr();" />
    </div>
    <table align="center" border="1" id="tbEmp" name="tbEmp" style="border-collapse: collapse" width="99%">
        <tr id="data_head" style="background-color: #e4e7e2">
           <td style="text-align: center"></td>
	        <td style="text-align: center">员工姓名</td>
	        <td style="text-align: center">员工编号</td>
	        <td style="text-align: center">部门</td>
	        <td style="text-align: center"> 岗位</td>
        </tr>
        <tr style="display:none">
            <td>
                <input type="checkbox" id="chktr" name="chktr" />
            </td>
	        <td>
		        <input  id="EmployeeID" name="EmployeeID" type="hidden" value="" />
                <input  id="txtEmployeeID" name="txtEmployeeID" readonly="readonly" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
                <button id="btnempId" name="emp" onclick="SelectEmployee(this);" type="button">选择</button>
            </td>
	        <td>
		        <input  id="EmployeeCode" name="EmployeeCode" readonly="readonly" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
            </td>
	        <td>
		        <input id="DeptName" name="DeptName" readonly="readonly" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
            </td>
	        <td>
		        <input id="PostName" name="PostName" readonly="readonly" style="border-bottom-style: none; border-bottom-color: transparent; border-right-style: none; border-top-color: transparent; border-top-style: none; border-right-color: transparent; border-left-style: none; border-left-color: transparent" type="text" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
